package com.zmcc.service.impl;

import com.google.gson.Gson;
import com.zmcc.entity.*;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.service.ISmsSendRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SmsSendRequestCommericial implements ISmsSendRequest {

    private final static String url = "https://dev.cmccopen.cn/api";

    private static SmsSendRequestCommericial smsSendRequestCommericial;

    public static synchronized SmsSendRequestCommericial getInstance() {
        if (smsSendRequestCommericial == null) {
            smsSendRequestCommericial = new SmsSendRequestCommericial();
        }
        return smsSendRequestCommericial;
    }

    @Override
    public CommonRequest getSmsSendRequest(SmsSendTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/send");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getSmsDeliveryStatusRequest(String messageId, String date, String san) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/deliveryStatus");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("messageId",messageId);
        bodyMap.put("date",date);
        bodyMap.put("san",san);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSmsSubscribeRequest(String smsURL, String san, String flg) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/subscribe");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("smsURL",smsURL);
        bodyMap.put("san",san);
        bodyMap.put("flg",flg);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSmsAddSignnatureRequest(SmsSignatureTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/signature"+"/add");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getSmsQuerySignnatureRequest(List<String> signatureNames) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/signature"+"/query");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("signatureNames",signatureNames);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSmsDelSignnatureRequest(List<SignatureElement> signatureList) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/signature"+"/del");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("signatureList",signatureList);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSmsAddTemplateRequest(SmsTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/template"+"/add");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getSmsDelTemplateRequest(List<Integer> templateIds) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/template"+"/del");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("templateIds",templateIds);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getSmsQueryTemplateRequest(List<String> templateIds) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1"+"/sms" +"/template"+"/query");
        Map<String,Object> bodyMap = new HashMap<>();
        bodyMap.put("templateIds",templateIds);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }
}
